package org.zmhhxl.user.controller.api;

import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RestController;
import org.zmhhxl.api.auth.domain.entity.UserInfo;
import org.zmhhxl.common.core.domain.Result;
import org.zmhhxl.user.service.UserInfoService;

//@RequiredArgsConstructor
@RestController
@AllArgsConstructor
@Slf4j
public class UserInfoApiController {
    public static final String USER_INFO_API = "/user/info";

   private final UserInfoService userInfoService;

   //@PreAuthorize("hasAuthority('user')")    //user:read
   @GetMapping("/user/find_by_username/{username}")
   Result<UserInfo> findByUsername(@PathVariable("username") String username)
   {
      log.info("findByUsername:====={}", username);
      return Result.ok(userInfoService.findByUsername(username));
   }

   @GetMapping("/user/find_by_id/{userId}")
   UserInfo findById(@PathVariable("userId") Long id)
   {
      // Optional<UserInfo> userInfo = userInfoService.findById(id);
      return userInfoService.findById(id).get();
   }
}
